﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_ViewMenu.cshtml";
}
<script src="/Content/After/js/jquery.min.js"></script>
<script>
    $(function () {
        pager(1);
    })
    function pager(a) {

        var PageSize = $("#PageSize").val();
        if (PageSize == "" || parseInt(PageSize) == 0 || PageSize == null) {
            PageSize = 10;
        }
        $.ajax({
            type: 'POST',
            url: '/UserInfo/Fnpagerdo',
            data: {
                pageindex: a,
                pagesize: PageSize
            },
            dataType: 'Json',
            success: function (mes) {
                var sex = "";
                var state = "";
                var tr = "";
                $(mes.PageList).each(function (i, obj) {
                    if (obj.UserSex == 1) {
                        sex = "男";
                    }
                    else {
                        sex = "女";
                    }
                    if (obj.UserState == 1) {
                        state = "启用";
                    }
                    else {
                        state = "禁用";
                    }
                    //<a href='#'  onclick='delUserInfo(" + obj.UserId + ",1)'>启用</a>
                    //<a href='#'  onclick='delUserInfo(" + obj.UserId + ",0)'>禁用</a>

                    if (obj.UserState == 1) {
                        tr += "<tr><td>" + obj.UserName + "</td><td>" + obj.UserChineseName + "</td><td>" + sex + "</td><td>" + obj.UserPhone + "</td><td>" + state + "</td><td>" + obj.DepartName + "</td><td><a href='#'  onclick='delUserInfo(" + obj.UserId + ",0)'>禁用</a> | <a href='#'  onclick='updaUserInfo(" + obj.UserId + ")'>修改</a></td></tr>";
                    }
                    else {
                        tr += "<tr><td>" + obj.UserName + "</td><td>" + obj.UserChineseName + "</td><td>" + sex + "</td><td>" + obj.UserPhone + "</td><td>" + state + "</td><td>" + obj.DepartName + "</td><td><a href='#'  onclick='delUserInfo(" + obj.UserId + ",1)'>启用</a> | <a href='#'  onclick='updaUserInfo(" + obj.UserId + ")'>修改</a></td></tr>";
                    }

                })
                $("#tbUserInfo tbody").html(tr);
                var divDemo = new Array();
                PageDemoSuccess(divDemo, mes)
                $("#pager").html(divDemo.join(""));
               
            }
        })
    }
    function delUserInfo(UserId, state) {
        $.ajax({
            type: 'POST',
            url: '/UserInfo/FndelUserInfo',
            data: {
                UserId: UserId, state: state
            },
            dataType: 'Json',
            success: function (mes) {
                if (mes > 0) {
                    alert("状态已修改！");
                    location.href = "/UserInfo/Index";

                }
                else {
                    alert("修改失败！");
                }
            }
        })
    }

    function updaUserInfo(UserId) {
        location.href = "/UserInfo/updaUserInfo/" + UserId;
    }
    //分页索引条加载方法
    function PageDemoSuccess(divDemo, data) {
        divDemo.push("<nav>")
        divDemo.push("<ul class=\"pagination\">")
        divDemo.push("<li>")
        divDemo.push(" <span>每页");
        divDemo.push("<input type=\"text\" style=\"width:40px;height:5px\"class=\"inpMain\" id=\"PageSize\" value=\"")
        divDemo.push(data.PageSize);
        divDemo.push("\" placeholder=\"\" />");
        divDemo.push(" 条</span></li>")
        divDemo.push("<li><span>共" + data.PageCount + "页，第" + data.PageIndex + "页，共" + data.PageNum + "条</span></li>")
        divDemo.push("<li><span onclick=\"pager(1)\" aria-label=\"Previous\"><span aria-hidden=\"true\">首页</span></span></li>")
        if (data.PageIndex <= 1) {
            divDemo.push("<li class=\"disabled\"><span onclick=\"pager(1)\">上一页</span></li>")
        }
        else {
            divDemo.push("<li><span onclick=\"pager(" + (data.PageIndex - 1) + ")\">上一页</span></li>")
        }
        for (var i = 0; i < data.PageCount; i++) {
            if (data.PageCount > 8) {
                if (data.PageIndex == 1) {
                    if (i <= 3) {
                        if (i == 3) {
                            LiNoPush(divDemo);
                        } else {
                            LiJumpPush(data.PageIndex, i, divDemo)
                        }
                    } else {
                        break;
                    }
                }
                else if (data.PageIndex == data.PageCount) {

                    if (i >= (data.PageCount - 4)) {
                        if (i == data.PageCount - 4) {
                            LiNoPush(divDemo);
                        } else {
                            LiJumpPush(data.PageIndex, i, divDemo)
                        }
                    }
                    else {
                        continue;
                    }
                } else {
                    if ((data.PageIndex - 3) <= i && i <= (data.PageIndex + 1)) {
                        if (data.PageIndex - 3 == i) {
                            LiNoPush(divDemo);
                        } else if (data.PageIndex + 1 == i) {
                            LiNoPush(divDemo);
                        } else {
                            LiJumpPush(data.PageIndex, i, divDemo)
                        }
                    } else {
                        continue;
                    }
                }
            } else {
                LiJumpPush(data.PageIndex, i, divDemo)
            }
        }
        if (data.PageIndex == data.PageCount) {
            divDemo.push("<li class=\"disabled\"><span onclick=\"pager(" + data.PageCount + ")\">下一页</span></li>")
        }
        else {
            divDemo.push("<li><span onclick=\"pager(" + (data.PageIndex + 1) + ")\">下一页</span></li>")
        }
        divDemo.push(" <li><span onclick=\"pager(" + data.PageCount + ")\" aria-label=\"Next\"><span aria-hidden=\"true\">尾页</span></span></li>")
        divDemo.push("</ul>")
        divDemo.push("</nav>")
    }
    //分页链接跳转方法
    function LiJumpPush(PageIndex, Num, Demo) {
        Demo.push("<li ")
        if (PageIndex == (Num + 1)) {
            Demo.push(" class=\"active\"")
        }
        Demo.push("><span onclick=\"pager(" + (Num + 1) + ")\">" + (Num + 1) + "</span></li>")
    }
    //省略号加载方法
    function LiNoPush(Demo) {
        Demo.push("<li><span>...</span></li>")
    }
</script>
<!-- 当前位置 -->
<div id="urHere">DouPHP 管理中心<b>&gt;</b><strong>挂号信息</strong> </div>
<div style="width:100%">
    <div class="mainBox" style="height:auto!important;height:550px;min-height:550px;">

        <h3><a href="/UserInfo/addUserInfo" class="actionBtn add">添加账号</a>用户显示</h3>
        <table id="tbUserInfo" width="100%" class="table table-bordered  tableBasic">
            <thead>
                <tr>
                    <th>登陆账号</th>
                    <th>真实姓名</th>
                    <th>性别</th>
                    <th>电话</th>
                    <th>状态</th>
                    <th>科室</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
        <div id="pager"></div>

    </div>

</div>